<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <canvas
      id="myCanvas"
      style="border: 1px solid #d3d3d3"
      width="600"
      height="600"
    ></canvas>
    <!-- 绘制矩形方法1 -->
    <!-- <script>
      var canvas = document.getElementById("myCanvas");
      var ctx = canvas.getContext("2d");
      ctx.beginPath();
      ctx.fillStyle = "red";
      ctx.moveTo(100, 50);
      ctx.lineTo(400, 50);
      ctx.lineTo(400, 300);
      ctx.lineTo(100, 300);
      ctx.lineTo(100, 50);
      ctx.fill();
      ctx.stroke();
    </script> -->

    <!-- 方法2 -->
    <!-- <script>
      var canvas = document.getElementById("myCanvas");
      var ctx = canvas.getContext("2d");
      ctx.fillRect(100, 100, 400, 300);
    </script> -->

    <!-- 方法3 -->
    <!-- <script>
      /** @type {HTMLCanvasElement} */
      var canvas = document.getElementById("myCanvas");
      var ctx = canvas.getContext("2d");
      ctx.lineWidth = 5;
      ctx.strokeRect(50, 50, 200, 100);
    </script> -->

    <!-- 方法4 -->
    <script>
      /** @type {HTMLCanvasElement} */
      var canvas = document.getElementById("myCanvas");
      var ctx = canvas.getContext("2d");
      ctx.beginPath();
      // 绘制矩形路径
      ctx.rect(10, 10, 200, 100);
      // 填充
      ctx.fillStyle = "red";
      ctx.fill();
      // 边框
      ctx.lineWidth = "5";
      ctx.strokeStyle = "blue";
      ctx.stroke();
    </script>
  </body>
</html>
